package com.example.bilibili.home;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.bilibili.Constants;
import com.example.bilibili.GoodsBean;
import com.example.bilibili.GoodsInfoActivity;
import com.example.bilibili.R;
import com.example.bilibili.ResultBeanData;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerClickListener;
import com.youth.banner.listener.OnLoadImageListener;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RemenFragmentAdapter extends RecyclerView.Adapter{

    private LayoutInflater mLayoutInflater;
    private Context mContext;
    public static final int REMEN = 0;

    private ResultBeanData.ResultBean resultBean;


    public RemenFragmentAdapter(Context mContext, ResultBeanData.ResultBean resultBean) {
        this.mContext = mContext;
        this.resultBean = resultBean;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new RemenViewHolder(mContext, mLayoutInflater.inflate(R.layout.remen_item, null));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        RemenViewHolder RemenViewHolder = (RemenViewHolder) holder;
        RemenViewHolder.setData(resultBean.getHot_info());

    }


    private void startGoodsInfoActivity(GoodsBean goodsBean) {
        Intent intent = new Intent(mContext, GoodsInfoActivity.class);
        intent.putExtra("GOODS_BEAN",goodsBean);
        mContext.startActivity(intent);
    }


    @Override
    public int getItemViewType(int position) {
        return REMEN;
    }

    @Override
    public int getItemCount() {
        //开发过程中从1-->6
        return 1;
    }


    class RemenViewHolder extends RecyclerView.ViewHolder{

        private final Context mContext;

        private GridView gv_Remen;

        public RemenViewHolder(final Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            gv_Remen = (GridView) itemView.findViewById(R.id.gv_remen);

        }

        public void setData(final List<ResultBeanData.ResultBean.HotInfoBean> Remen_info) {
            //1.有数据
            //2.设置GridView的适配器
            RemenGridViewAdapter  adapter = new RemenGridViewAdapter(mContext,Remen_info);
            gv_Remen.setAdapter(adapter);


            //设置item的监听
            gv_Remen.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    ResultBeanData.ResultBean.HotInfoBean RemenInfoBean1 =  Remen_info.get(position);
                    String SHotposition = RemenInfoBean1.getHotposition();
                    try {
                        int Hotposition = Integer.parseInt(SHotposition);
                        ResultBeanData.ResultBean.HotInfoBean RemenInfoBean =  Remen_info.get(Hotposition);
                        GoodsBean goodsBean = new GoodsBean();
                        goodsBean.setFensi(RemenInfoBean.getFensi());
                        goodsBean.setBofangliang(RemenInfoBean.getBofangliang());
                        goodsBean.setCommennt(RemenInfoBean.getCommennt());
                        goodsBean.setFensi(RemenInfoBean.getFigure());
                        goodsBean.setName(RemenInfoBean.getName());
                        goodsBean.setTime(RemenInfoBean.getTime());
                        goodsBean.setRed(RemenInfoBean.getRed());
                        goodsBean.setTouxiang(RemenInfoBean.getTouxiang());
                        goodsBean.setShijian(RemenInfoBean.getShijian());
                        goodsBean.setFensi(RemenInfoBean.getFensi());
                        goodsBean.setDianzan(RemenInfoBean.getDianzan());
                        goodsBean.setToubi(RemenInfoBean.getToubi());
                        goodsBean.setShoucang(RemenInfoBean.getShoucang());
                        goodsBean.setZhuanfa(RemenInfoBean.getZhuanfa());
                        goodsBean.setShipin(RemenInfoBean.getShipin());
                        goodsBean.setId(RemenInfoBean.getId());
                        goodsBean.setC1(RemenInfoBean.getC1());
                        goodsBean.setC2(RemenInfoBean.getC2());
                        goodsBean.setC3(RemenInfoBean.getC3());
                        goodsBean.setHotposition(RemenInfoBean.getHotposition());
                        startGoodsInfoActivity(goodsBean);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }

                }
            });
        }
    }
}

